﻿@using ZBJF.Warranty.Common.Enums
@using ZBJF.Warranty.WebProvider
@using ZBJF.Warranty.WebProvider.AdminPemission
@section Header{
    @Styles.Render("~/Content/chosen")
}
@{
    var result = RightHelper.Instance.GetAllPageMenu().OrderBy(o => o.BelongApplicationType).ThenBy(o => o.OrderIndex).ToList();
}
<div class="breadcrumbs" id="breadcrumbs">
    <ul class="nav nav-tabs">
        <li class="active"><a href="/System/PageMenu">菜单列表</a></li>
    </ul>
</div>
<form id="searchForm" class="breadcrumb form-search">
    <div>
        <a id="AddNewRole" class="btn btn-xs btn-primary Add-R" data-toggle="modal" href="" onclick="showLayerOpen('添加新菜单', '/System/PageMenu/Edit/0', '500px', '60%')" title="添加新菜单">
            <i class="icon-plus-sign bigger-130"></i>
            添加新菜单
        </a>
    </div>
</form>
<div class="categoryTree">
    <table class="table table-striped table-bordered table-hover">
        <thead>
            <tr>
                <th>菜单名称</th>
                <th>所属系统</th>
                <th>图标样式</th>
                <th>菜单路径</th>
                <th>菜单按钮</th>
                <th>是否显示为左侧菜单</th>
                <th>排序</th>
                <th>管理操作</th>
            </tr>
        </thead>
        <tbody>
            @Html.Action("ShowMenuList", "PageMenu", new { listPage = result, pid = 0, layer = 0 })
        </tbody>
    </table>
</div>
<div class="modal fade" id="ShowAction" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
    @RenderPage("DisplayTemplates/PageMenuActions.cshtml")
</div>
@section scripts{
    @Scripts.Render("~/bundles/chosen")
    @Scripts.Render("~/bundles/permission")
    <script type="text/javascript">
        $(function () {
            $("#ParentID").chosen();
            $("#ActionListId").chosen();
        });

        function UpdateAction(id) {
            $("#UpdateActionId").val(id);
            $.ajax({
                url: "/System/PageMenu/GetPageAction",
                type: "post",
                data: { id: id },
                success: function (result) {
                    if (result.success) {
                        $("#ActionListId option").each(function () {
                            $(this).attr("selected", false);
                        });

                        if (result.PageActionIDList != null && result.PageActionIDList != "") {
                            var stringId = result.PageActionIDList.split(',');
                            for (var i = 0; i < stringId.length; i++) {
                                $("#ActionListId option[value='" + stringId[i] + "']").attr("selected", "selected");
                            }
                        }

                        $("#ActionListIdSelect").html($("#ActionListId"));

                        $("#ActionListId").chosen();
                        showBSModalDialog("ShowAction", "600", "300");

                    } else {
                        layer.alert(result.message);
                    }
                }
            });
        }

        function UpdateActionSubmit() {
            var listId = $("#ActionListId").val();
            var actionListId = "";
            if (listId != null) {
                for (var i = 0; i < listId.length; i++) {
                    if (actionListId === "") {
                        actionListId += listId[i];
                    } else {
                        actionListId += "," + listId[i];
                    }
                }
            }
            $.ajax({
                type: "post",
                url: "/System/PageMenu/UpdateAction",
                data: { id: $("#UpdateActionId").val(), ActionListId: actionListId },
                success: function (result) {
                    $('#ShowAction').modal('hide'); //关闭模态框
                    if (result.success) {
                        layer.alert(result.message, {
                            yes: function () {
                                layer.closeAll();
                            }
                        });
                    } else {
                        layer.alert(result.message);
                    }
                }
            });
        }
    </script>
}
